
//------------------------------------------------------------------------      	
	
	function showStandard(e) {

		var str = $("#original_text").val();
		str = jQuery.trim(str);
		$("#original_text").val(str);
		
		$.ajax({
			type : "POST",
			url : "symptomsSearch.do",
			dataType : 'json',

			data : {
				original_text : $("#original_text").val(),
				button : "1"
			},

			error : function(xhr) {
				alert("Ajax request error!1");

			},
			success : function(DataList) {
				var text_new = "";
				var text_new_not_in_db = "";
				var pattern = "";
				var in_database = false;
				$.each(DataList, function(index, Data) {

					$.each(Data.modified_Data_list, function(index,
							modified_Data) {

						if (modified_Data.modified != "不存在資料庫") {
							pattern = pattern + modified_Data.modified + "。";
							in_database = true;
						}
					});

					if (in_database) {

						text_new = text_new + Data.org + "。"+ "\n";
						//pattern = pattern.substring(0, pattern.length-1);
						pattern = pattern + "\n";

					} else {

						text_new_not_in_db = text_new_not_in_db + Data.org
								+ "。";

					}

					in_database = false;

				});
				$("#original_text").val(text_new);
				$("#test").val(pattern);
				
				$("#original_text_partial").val(text_new_not_in_db);

				if ($.trim($("#original_text_partial").val()) != '') {
					showStandard_partial();
					
				}

			}
		});
	}
	//-----------------------------------------------------------------------
	function showOriginal(e) {
		var str = $("#test").val();
		str = jQuery.trim(str);
		$("#test").val(str);

		$.ajax({
			type : "POST",
			url : "symptomsSearch.do",
			dataType : 'json',

			data : {
				test_text : $("#test").val(),
				button : "2"
			},

			error : function(xhr) {
				alert("Ajax request error!2");
			},
			success : function(ModifyList) {
				var text_new = "";
				var pattern = "";
				$.each(ModifyList, function(index, Modify) {

					text_new = text_new + Modify.modified + "。" + "\n";

					$.each(Modify.Data_list, function(index, Data) {

						pattern = pattern + Data.org + "。";

					});

					pattern = pattern + "\n" + "\n";
				});
				$("#original_text").val(pattern);
				$("#test").val(text_new);

			}
		});
	}

	//--------------------------------------------------------------------------
	function showStandard_partial(e) {

		var str = $("#original_text_partial").val();
		str = jQuery.trim(str);
		$("#original_text_partial").val(str);
		
		$.ajax({
			type : "POST",
			url : "symptomsSearch.do",
			dataType : 'json',

			data : {
				original_text_partial : $("#original_text_partial").val(),
				button : "3"
			},

			error : function(xhr) {
				alert("Ajax request error!3");

			},
			success : function(DataList) {
				var text_new = "";
				var pattern = "";
				$.each(DataList, function(index, Data) {

					text_new = text_new + Data.org + "。"+ "\n";

					$.each(Data.modified_Data_list, function(index,
							modified_Data) {
						
						if(modified_Data.modified != "不存在資料庫"){
							pattern = pattern + modified_Data.modified + "。";	
						}
						else{
							
							pattern = pattern + "沒有建議症狀" + "。";
							
							
						}
						

					});
					//pattern = pattern.substring(0, pattern.length-1);
					pattern = pattern + "\n";

				});
				$("#original_text_partial").val(text_new);
				$("#standard_text_partial").val(pattern);
				
				WriteToDatabase();

			}
		});
	}
	//-----------------------------------------------------------------------
	function WriteToDatabase(e) {
		var str = $("#original_text_partial").val();
		
		str = jQuery.trim(str);
		var str2 = $("#standard_text_partial").val();
		str2 = jQuery.trim(str2);
		
		$.ajax({
			type : "POST",
			url : "symptomsSearch.do",
			dataType : 'text',
			data : {
				str : str,
				str2 : str2,
				button : "4"
			},

			error : function(xhr) {

			},
			success : function(Data) {
				if (Data = "success") {

					//alert("儲存成功");

				}

			}
		});
		
		
	}
	//-----------------------------------------------------------------------
	function ExportToExcel_1(e) {

		$(function() {

			var str = $("#original_text").val();
			str = jQuery.trim(str);
			

			var str2 = $("#test").val();
			str2 = jQuery.trim(str2);

			$.ajax({
				type : "POST",
				url : "symptomsSearch.do",
				dataType : 'text',
				data : {
					str : str,
					str2 : str2,
					button : "excel"
				},

				error : function(xhr) {

				},
				success : function(Data) {
					if (Data = "success") {

						alert("匯出成功");

					}

				}
			});

		});

	}
	//-----------------------------------------------------------------------
	function ExportToExcel_2(e) {

		$(function() {

			var str = $("#original_text_partial").val();
			str = jQuery.trim(str);

			var str2 = $("#standard_text_partial").val();
			str2 = jQuery.trim(str2);

			$.ajax({
				type : "POST",
				url : "symptomsSearch.do",
				dataType : 'text',
				data : {
					str : str,
					str2 : str2,
					button : "excel"
				},

				error : function(xhr) {

				},
				success : function(Data) {
					if (Data = "success") {

						alert("匯出成功");

					}

				}
			});

		});

	}
	//-----------------------------------------------------------------------
	$(document).ready(function(e) {

		document.getElementById("dialog-confirm").style.display = "none";//隱藏		
		$("input[type=button]").button().click(function(event) {
			event.preventDefault();
		});

		$("#clickBtn").click(showStandard);
		$("#originalBtn").click(showOriginal);

		$("#clickBtn_partial").click(showStandard_partial);
		//$("#WriteToDatabase").click(WriteToDatabase);
		$("#ExportToExcel_1").click(ExportToExcel_1);
		$("#ExportToExcel_2").click(ExportToExcel_2);
	});